import { Button } from 'antd';
import {WeaDialog ,WeaNewScroll,WeaSearchGroup,WeaLocaleProvider,WeaTab,WeaFormItem} from 'ecCom';
import {observer} from "mobx-react";
import {toJS} from 'mobx';
import {WeaTableNew,WeaSwitch} from 'comsMobx';
const WeaTable = WeaTableNew.WeaTable;
const getLabel = WeaLocaleProvider.getLabel;

@observer
class CptModifyLogDialog extends React.Component {
    constructor(props) {
        super(props);
    }

    shouldComponentUpdate(nextProps,nextState){
        return true;
    }
 
    render() {
        const {store} = this.props;
        const {showSearchAd,modifyTableStore} = store;
        return (
            <div>
            <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@sxyh38`}
                title={getLabel(83,"日志")}
                visible={store.modifylogVisible}
                buttons={this.getButtons()}
                icon="icon-coms-ModelingEngine"
                iconBgcolor="#217346"
                onCancel={()=>{store.setModifylogVisible(false)}}
                style={{width:'700px', height:'400px'}}
            >
                    <WeaNewScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaNewScroll@as008c`} height={"100%"}>
                        <WeaTab ecId={`${this && this.props && this.props.ecId || ''}_WeaTab@nu5a40`}
                            buttonsAd={this.getAdButtons()}
                            searchType={['advanced']}
                            setShowSearchAd={bool=>{store.setShowSearchAd(bool)}}
                            hideSearchAd={()=> store.setShowSearchAd(false)}
                            searchsAd={
                                <div>{this.getCondition()}</div>
                            }
                            showSearchAd={showSearchAd}
                        />
                        <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@zx5rmb`} 
                            comsWeaTableStore={modifyTableStore}
                            hasOrder={true}
                            needScroll={false}
                        />
                    </WeaNewScroll>
            </WeaDialog>
        </div>)
    }
    getButtons(){
        const {store} = this.props;
        let btnArr = []; 
        btnArr.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@fjjgvg@close`}  type="primary" onClick={()=>store.setModifylogVisible(false)}>{getLabel(309,"关闭")}</Button>)  
        return btnArr;
    }

    getAdButtons = () => {
        const {store} = this.props;
        const {getModifyList,setShowSearchAd,clearFormFields1} = store;
        return [
            (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@a1zkso@search`} type="primary" onClick={()=>{getModifyList();setShowSearchAd(false);}}>{getLabel(197,'搜索') }</Button>),
            (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@10vxzi@reset`} type="ghost" onClick={()=>{clearFormFields1();}}>{getLabel(2022,'重置') }</Button>),
            (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@jjyrg6@close`} type="ghost" onClick={()=>{setShowSearchAd(false)}}>{getLabel(201,'取消') }</Button>)
        ];
    }
    getCondition=()=>{
        const { cptModifyCondition, modifyForm, getModifyList, setShowSearchAd } = this.props.store;
        const {isFormInit} = modifyForm;
        let group = [];
        isFormInit &&  cptModifyCondition.map((c,i) =>{
          let items = [];
          c.items.map((fields,index) => {
            items.push({
              com:(<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@oti81o@${fields.domkey[0]}`}
                  label={`${fields.label}`}
                  labelCol={{span: `${fields.labelcol}`}}
                  wrapperCol={{span: `${fields.fieldcol}`}}>
                        <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@19ki6p@${fields.domkey[0]}`} fieldConfig={fields} form={modifyForm} onEnterSearch={this.onEnterSearch} />
                  </WeaFormItem>),
              colSpan:1,
            })
          });
          group.push(<WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@n9zcmz@${i}`} needTigger={true} title={c.title} showGroup={c.defaultshow} items={items}/>)
        });
        return group;
    }

    onEnterSearch = () =>{
        const { getModifyList, setShowSearchAd } = this.props.store;
        getModifyList();
        setShowSearchAd(false);
    }
   
}

export default CptModifyLogDialog;